pull: Check the remote repo type
authorColin Walters <walters@verbum.org>
Sat, 15 Sep 2012 16:34:04 +0000 (12:34 -0400)
committerColin Walters <walters@verbum.org>
Sat, 15 Sep 2012 16:41:25 +0000 (12:41 -0400)
We can only pull from archive repositories right now.  This will also
be useful for adding compressed archives later.

src/libostree/ostree-repo.c
src/libostree/ostree-repo.h
src/ostree/ostree-pull.c

index 15843dad609d1ee845902f26a8d902aa705ebe01..9bd44f17a49afa1580b9c9ef020b0de9679a49b3 100644 (file)
@@ -586,6 +586,31 @@ ostree_repo_write_config (OstreeRepo *self,
   return ret;
 }
 
+gboolean
+ostree_repo_mode_from_string (const char      *mode,
+                              OstreeRepoMode  *out_mode,
+                              GError         **error)
+{
+  gboolean ret = FALSE;
+  OstreeRepoMode ret_mode;
+
+  if (strcmp (mode, "bare") == 0)
+    ret_mode = OSTREE_REPO_MODE_BARE;
+  else if (strcmp (mode, "archive") == 0)
+    ret_mode = OSTREE_REPO_MODE_ARCHIVE;
+  else
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Invalid mode '%s' in repository configuration", mode);
+      goto out;
+    }
+
+  ret = TRUE;
+  *out_mode = ret_mode;
+ out:
+  return ret;
+}
+
 gboolean
 ostree_repo_check (OstreeRepo *self, GError **error)
 {
@@ -641,16 +666,8 @@ ostree_repo_check (OstreeRepo *self, GError **error)
                                               "bare", &mode, error))
         goto out;
 
-      if (strcmp (mode, "bare") == 0)
-        self->mode = OSTREE_REPO_MODE_BARE;
-      else if (strcmp (mode, "archive") == 0)
-        self->mode = OSTREE_REPO_MODE_ARCHIVE;
-      else
-        {
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                       "Invalid mode '%s' in repository configuration", mode);
-          goto out;
-        }
+      if (!ostree_repo_mode_from_string (mode, &self->mode, error))
+        goto out;
     }
 
   if (!ot_keyfile_get_value_with_default (self->config, "core", "parent",
index 7edc635d61ae94a795b52acadfe5a5ad2788c4ef..5f5e0dfa53a0944b31c205ebc125e9556962230d 100644 (file)
@@ -47,6 +47,10 @@ typedef enum {
   OSTREE_REPO_MODE_ARCHIVE
 } OstreeRepoMode;
 
+gboolean       ostree_repo_mode_from_string (const char      *mode,
+                                             OstreeRepoMode  *out_mode,
+                                             GError         **error);
+
 OstreeRepoMode ostree_repo_get_mode (OstreeRepo  *self);
 
 GFile *       ostree_repo_get_tmpdir (OstreeRepo  *self);
index 0115b8b9d096ad1d620407d7dd3a0af259911199..f1804dab96ae9f287b446496acd33cb63438c816 100644 (file)
@@ -1459,6 +1459,35 @@ repo_get_string_key_inherit (OstreeRepo          *repo,
   return ret;
 }
 
+static gboolean
+load_remote_repo_config (OtPullData    *pull_data,
+                         GKeyFile     **out_keyfile,
+                         GCancellable  *cancellable,
+                         GError       **error)
+{
+  gboolean ret = FALSE;
+  ot_lfree char *contents = NULL;
+  GKeyFile *ret_keyfile = NULL;
+  SoupURI *target_uri = NULL;
+
+  target_uri = suburi_new (pull_data->base_uri, "config", NULL);
+  
+  if (!fetch_uri_contents_utf8 (pull_data, target_uri, &contents,
+                                cancellable, error))
+    goto out;
+
+  ret_keyfile = g_key_file_new ();
+  if (!g_key_file_load_from_data (ret_keyfile, contents, strlen (contents),
+                                  0, error))
+    goto out;
+
+  ret = TRUE;
+  ot_transfer_out_value (out_keyfile, &ret_keyfile);
+ out:
+  g_clear_pointer (&ret_keyfile, (GDestroyNotify) g_key_file_unref);
+  return ret;
+}
+
 static gboolean
 ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
 {
@@ -1468,6 +1497,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   gpointer key, value;
   int i;
   GCancellable *cancellable = NULL;
+  OstreeRepoMode remote_repo_mode;
   ot_lfree char *remote_key = NULL;
   ot_lobj OstreeRepo *repo = NULL;
   ot_lfree char *path = NULL;
@@ -1477,10 +1507,12 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   ot_lhash GHashTable *updated_refs = NULL;
   ot_lhash GHashTable *commits_to_fetch = NULL;
   ot_lfree char *branch_rev = NULL;
+  ot_lfree char *remote_mode_str = NULL;
   OtPullData pull_data_real;
   OtPullData *pull_data = &pull_data_real;
   SoupURI *summary_uri = NULL;
   GKeyFile *config = NULL;
+  GKeyFile *remote_config = NULL;
   char **configured_branches = NULL;
   guint64 bytes_transferred;
 
@@ -1526,6 +1558,26 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
       goto out;
     }
 
+  if (!load_remote_repo_config (pull_data, &remote_config, cancellable, error))
+    goto out;
+
+  if (!ot_keyfile_get_value_with_default (remote_config, "core", "mode", "bare",
+                                          &remote_mode_str, error))
+    goto out;
+
+  if (!ostree_repo_mode_from_string (remote_mode_str, &remote_repo_mode, error))
+    goto out;
+
+  switch (remote_repo_mode)
+    {
+    case OSTREE_REPO_MODE_ARCHIVE:
+      break;
+    default:
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Can't pull from archives with mode \"%s\"",
+                   remote_mode_str);
+    }
+
   requested_refs_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   updated_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   commits_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -1701,6 +1753,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   g_clear_pointer (&pull_data->file_checksums_to_fetch, (GDestroyNotify) g_hash_table_unref);
   g_clear_pointer (&pull_data->cached_meta_pack_indexes, (GDestroyNotify) g_ptr_array_unref);
   g_clear_pointer (&pull_data->cached_data_pack_indexes, (GDestroyNotify) g_ptr_array_unref);
+  g_clear_pointer (&remote_config, (GDestroyNotify) g_key_file_unref);
   if (summary_uri)
     soup_uri_free (summary_uri);
   return ret;